<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{    
    function _initAutoLoad() {
		$autoLoader = Zend_Loader_Autoloader::getInstance();

		$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
				'basePath' 	=>   APPLICATION_PATH,
				'namespace'  =>  'Vina',
				'resourceTypes'  =>   array (
						'form'   =>  array (
								'path'        =>   'forms', 
								'namespace'   =>   'Form_'), 
						'validate'   =>  array (
								'path'        =>   'views/validation', 
								'namespace'   =>   'Validate_'),		
						'plugin'   =>  array (
								'path'        =>   'plugins', 
								'namespace'   =>   'Plugin_'),
						'service'   =>  array (
								'path'        =>   'services', 
								'namespace'   =>   'Service_'),
						'model'   =>  array (
								'path'        =>   'models', 
								'namespace'   =>   'Model_'),
						'helper'   =>  array (
								'path'        =>   'helpers', 
								'namespace'   =>   'Helper_'),
    		),
		));
		
		$autoLoader->setFallbackAutoloader(true);
		
		//Call Zend_Acl plugin
		$zcf = Zend_Controller_Front::getInstance();
		//$zcf->registerPlugin(new Butler_Plugin_Acl());

		return $autoLoader;
	}        
	protected function _initPlugins()
	{	    
	    $this->bootstrap('frontController');
	    // The ACL
	    $this->frontController->registerPlugin(new Vina_Plugin_Layout());	    
	}	
    protected function _initFrontController(){
       $front = Zend_Controller_Front::getInstance();       
       $front->setControllerDirectory(
          array(
              'default' => APPLICATION_PATH."/modules/default/controllers",
              'admin'  => APPLICATION_PATH."/modules/admin/controllers",
          ));
       
       $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routers.ini', 'thietlap');
      $router = new Zend_Controller_Router_Rewrite();
      
      $router = $router->addConfig($config, 'routes');
      
      $front->setRouter($router);
                      
       return $front;
    }
	protected function _initRestRoute()
	{
	 				
	}         
	protected function _initRequest()
    {
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');
        $request = $front->getRequest();
    	if (null === $front->getRequest()) {
            $request = new Zend_Controller_Request_Http();
            $front->setRequest($request);
        }
        
    	return $request;        
    } 		
    
    protected function _initTimeZone()
    {
        // to use default GMT date time
        date_default_timezone_set('Europe/Dublin');        
    }
    
    
	protected function _initConstant()
    {
        // to use default GMT date time
        require_once APPLICATION_PATH . '/'. 'Constant.php';        
    }
	protected function _initDb() {
	
		$dbOption = $this->getOption('resources');
    	$dbOption = $dbOption['db'];
    	
        // Setup database
        $db = Zend_Db::factory($dbOption['adapter'],$dbOption['params']);
       
        $db->setFetchMode(Zend_Db::FETCH_ASSOC);
        $db->query("SET NAMES 'utf8'");
        $db->query("SET CHARACTER SET 'utf8'");
       
        Zend_Registry::set('connectDB',$db);
                
        //Khi thiet lap che do nay model moi co the su dung duoc
        Zend_Db_Table::setDefaultAdapter($db);
        
        // Return it, so that it can be stored by the bootstrap
        return $db;
	}

}

